#include "tree_print.h"
#include <stdio.h>

void print_indents(int count) {
	int i;
	for(i=0;i<count;i++) {
		printf("\t");
	}
}
void print_indented_string(int count,char* string) {
	int i;
	for(i=0;i<count;i++)
		printf("\t");
	puts(string);
}
int tree_print(void) {
  if(root && root->pMSTL) {
	  puts("<program>");	
	  tree_print_mstl(root->pMSTL,1);
	  puts("</program>");
  }
  return 1;
}
void tree_print_mstl(struct MainStmtTagListInfo* pMSTL,int tab) {
	struct Tag* iterator;
	print_indents(tab);
	puts("<main_stmt_list_info>");
	iterator=pMSTL->pFirst;
	while(iterator) {
		tree_print_tag(iterator,tab+1);

		if(iterator->html && iterator->html->pNext) {
			iterator=iterator->html->pNext;
		}
		else {
			if(iterator->msti && iterator->msti->pNext) {
				iterator=iterator->msti->pNext;
			}
			else	
				iterator=NULL;
		}
		
	}
	print_indents(tab);
	puts("</main_stmt_list_info>");
}
void tree_print_stmtlist(struct StmtListInfo* stmtl,int tab) {
	struct StmtInfo* iterator = stmtl->pStmtFirst;
	while(iterator) {
		tree_print_stmt(iterator,tab+1);
		iterator=iterator->pStmtNext;
	}
}
void tree_print_tag(struct Tag* tag,int tab) {
	print_indents(tab);
	puts("<tag>");
	if(tag->msti)
		tree_print_mainstmt(tag->msti,tab+1);
		//tree_print_stmt(tag->msti->pStmtInfo,tab+1);
	if(tag->html) {
		print_indents(tab+1);
		puts("<html-block>");
		//puts("\"");
		//puts(tag->html->html);
		//puts("\"");
		print_indents(tab+1);
		puts("</html-block>");
	}
	print_indents(tab);
	puts("</tag>");
}
void tree_print_stmt(struct StmtInfo* msti,int tab) {
	print_indents(tab);
	puts("<stmt>");
	if(msti)
		switch(msti->type){
		case Expr:
			tree_print_expr(msti->pExprLeft,tab+1);
			break;
		case Echo:
			print_indents(tab+1);
			puts("<echo>");
			tree_print_expr(msti->pExprLeft,tab+2);
			print_indents(tab+1);
			puts("</echo>");
			break;
		case If:
			tree_print_if(msti->pIfStmt,tab+1);
			break;
		case stmt_list:
			print_indents(tab+1);
			puts("<stmt_list>");
			if(msti->pStmtBlock)
				tree_print_stmtlist(msti->pStmtBlock,tab+1);
			print_indents(tab+1);
			puts("</stmt_list>");
			break;
		case While:
			print_indents(tab+1);
			puts("<while-do>");
			
			print_indents(tab+2);
			puts("<while>");
			tree_print_expr(msti->pExprLeft,tab+3);
			print_indents(tab+2);
			puts("</while>");

			if(msti->pStmtLeft) {
				print_indents(tab+2);
				puts("<do>");
				tree_print_stmt(msti->pStmtLeft,tab+3);
				print_indents(tab+2);
				puts("</do>");
			}

			print_indents(tab+1);
			puts("</while-do>");
			break;
		case Dowhile:
			print_indents(tab+1);
			puts("<do-while>");
			
			if(msti->pStmtBlock) {
				print_indents(tab+2);
				puts("<do>");
				tree_print_stmtlist(msti->pStmtBlock,tab+2);
				print_indents(tab+2);
				puts("</do>");
			}

			print_indents(tab+2);
			puts("<while>");
			tree_print_expr(msti->pExprLeft,tab+3);
			print_indents(tab+2);
			puts("</while>");

			print_indents(tab+1);
			puts("</do-while>");
			break;
		case For:
			print_indents(tab+1);
			puts("<for>");
			if(msti->pExprLeft) {
				print_indents(tab+2);
				puts("<prepare>");
				tree_print_expr(msti->pExprLeft,tab+3);
				print_indents(tab+2);
				puts("</prepare>");
			}
			if(msti->pExprMid) {
				print_indents(tab+2);
				puts("<condition>");
				tree_print_expr(msti->pExprMid,tab+3);
				print_indents(tab+2);
				puts("</condition>");
			}
			if(msti->pExprRight) {
				print_indents(tab+2);
				puts("<afteraction>");
				tree_print_expr(msti->pExprRight,tab+3);
				print_indents(tab+2);
				puts("</afteraction>");
			}
			if(msti->pStmtLeft) {
				print_indents(tab+2);
				puts("<body>");
				tree_print_stmt(msti->pStmtLeft,tab+3);
				print_indents(tab+2);
				puts("</body>");				
			}
			print_indents(tab+1);
			puts("</for>");
			break;
		case Foreach:
			print_indents(tab+1);
			puts("<foreach>");
			
			print_indents(tab+2);
			puts("<foreach-array>");
			
			tree_print_expr(msti->pExprLeft,tab+3);
			
			print_indents(tab+2);
			puts("</foreach-array>");

			if(msti->VarnameLeft) {
				print_indents(tab+2);
				puts("<foreach-key>");
				
				print_indents(tab+3);
				puts(msti->VarnameLeft);
				
				print_indents(tab+2);
				puts("</foreach-key>");
			}

			print_indents(tab+2);
			puts("<foreach-value>");
			
			print_indents(tab+3);
			puts(msti->VarnameRight);
			
			print_indents(tab+2);
			puts("</foreach-value>");

			print_indents(tab+2);
			puts("<foreach-body>");
			
			tree_print_stmt(msti->pStmtLeft,tab+3);
			
			print_indents(tab+2);
			puts("</foreach-body>");

			print_indents(tab+1);
			puts("</foreach>");
			break;
		case Switch:
			tree_print_switch(msti->pSwitchStmt,tab+1);
			break;
		case Break:
			print_indents(tab+1);
			puts("<break/>");
			break;
		
		case Return:
			if(msti->pExprLeft) {
				print_indents(tab+1);
				puts("<return>");
				tree_print_expr(msti->pExprLeft,tab+2);
				print_indents(tab+1);
				puts("</return>");
			}
			else {
				print_indents(tab+1);
				puts("<return/>");
			}
			break;
		};	
	print_indents(tab);
	puts("</stmt>");
}
void tree_print_expr(struct ExprInfo* expr,int tab) {
	if(!expr)
		return;
	switch(expr->type){
		case var:
			print_indents(tab);
            printf("<var localIndex=\"%d\">\n",expr->localTableIndex);
			print_indents(tab+1);
			puts(expr->varname);
			print_indents(tab);
			puts("</var>");
			break;
		case intcnst:
			print_indents(tab);
			puts("<intcnst>");
			print_indents(tab+1);
			printf("%d\n",expr->const_int);
			print_indents(tab);
			puts("</intcnst>");
			break;
		case charcnst:
			print_indents(tab);
            printf("<charcnst constTableIndex=\"%d\">\n",expr->constTableIndex);
			print_indents(tab+1);
			puts(expr->const_char);
			print_indents(tab);
			puts("</charcnst>");
			break;
		case brac:
			print_indents(tab);
			puts("<brac>");
			tree_print_expr(expr->left,tab+1);
			tree_print_expr(expr->right,tab+1);
			print_indents(tab);
			puts("</brac>");
			break;
        case bracassign:
			print_indents(tab);
			puts("<bracassign>");
			tree_print_expr(expr->left,tab+1);
            tree_print_expr(expr->mid,tab+1);
			tree_print_expr(expr->right,tab+1);
			print_indents(tab);
			puts("</bracassign>");
			break;
		case assign:
			print_indents(tab);
			puts("<assign>");
			tree_print_expr(expr->left,tab+1);
			tree_print_expr(expr->right,tab+1);
			print_indents(tab);
			puts("</assign>");
			break;
		case mul:
			print_indents(tab);
			puts("<mul>");
			tree_print_expr(expr->left,tab+1);
			tree_print_expr(expr->right,tab+1);
			print_indents(tab);
			puts("</mul>");
			break;
		case cat:
			print_indents(tab);
			puts("<concatenate>");
			tree_print_expr(expr->left,tab+1);
			tree_print_expr(expr->right,tab+1);
			print_indents(tab);
			puts("</concatenate>");
			break;
        case add:
			print_indents(tab);
			puts("<add>");
			tree_print_expr(expr->left,tab+1);
			tree_print_expr(expr->right,tab+1);
			print_indents(tab);
			puts("</add>");
			break;
		case sub:
			print_indents(tab);
			puts("<sub>");
			tree_print_expr(expr->left,tab+1);
			tree_print_expr(expr->right,tab+1);
			print_indents(tab);
			puts("</sub>");
			break;
		case division:
			print_indents(tab);
			puts("<div>");
			tree_print_expr(expr->left,tab+1);
			tree_print_expr(expr->right,tab+1);
			print_indents(tab);
			puts("</div>");
			break;
		case modulo:
			print_indents(tab);
			puts("<modulo>");
			tree_print_expr(expr->left,tab+1);
			tree_print_expr(expr->right,tab+1);
			print_indents(tab);
			puts("</modulo>");
			break;
		case pas:
			print_indents(tab);
			puts("<pas>");
			tree_print_expr(expr->left,tab+1);
			tree_print_expr(expr->right,tab+1);
			print_indents(tab);
			puts("</pas>");
			break;
		case mas:
			print_indents(tab);
			puts("<mas>");
			tree_print_expr(expr->left,tab+1);
			tree_print_expr(expr->right,tab+1);
			print_indents(tab);
			puts("</mas>");
			break;
		case mulas:
			print_indents(tab);
			puts("<mulas>");
			tree_print_expr(expr->left,tab+1);
			tree_print_expr(expr->right,tab+1);
			print_indents(tab);
			puts("</mulas>");
			break;
		case divas:
			print_indents(tab);
			puts("<divas>");
			tree_print_expr(expr->left,tab+1);
			tree_print_expr(expr->right,tab+1);
			print_indents(tab);
			puts("</divas>");
			break;
		case modas:
			print_indents(tab);
			puts("<modas>");
			tree_print_expr(expr->left,tab+1);
			tree_print_expr(expr->right,tab+1);
			print_indents(tab);
			puts("</modas>");
			break;
		case pp_pre:
			print_indents(tab);
			puts("<pp_pre>");
			tree_print_expr(expr->left,tab+1);
			print_indents(tab);
			puts("</pp_pre>");
			break;
		case pp_post:
			print_indents(tab);
			puts("<pp_post>");
			tree_print_expr(expr->left,tab+1);
			print_indents(tab);
			puts("</pp_post>");
			break;
		case mm_pre:
			print_indents(tab);
			puts("<mm_pre>");
			tree_print_expr(expr->left,tab+1);
			print_indents(tab);
			puts("</mm_pre>");
			break;
		case mm_post:
			print_indents(tab);
			puts("<mm_post>");
			tree_print_expr(expr->left,tab+1);
			print_indents(tab);
			puts("</mm_post>");
			break;
		case eq:
			print_indents(tab);
			puts("<eq>");
			tree_print_expr(expr->left,tab+1);
			tree_print_expr(expr->right,tab+1);
			print_indents(tab);
			puts("</eq>");
			break;
		case ne:
			print_indents(tab);
			puts("<ne>");
			tree_print_expr(expr->left,tab+1);
			tree_print_expr(expr->right,tab+1);
			print_indents(tab);
			puts("</ne>");
			break;
		case teq:
			print_indents(tab);
			puts("<teq>");
			tree_print_expr(expr->left,tab+1);
			tree_print_expr(expr->right,tab+1);
			print_indents(tab);
			puts("</teq>");
			break;
		case tne:
			print_indents(tab);
			puts("<tne>");
			tree_print_expr(expr->left,tab+1);
			tree_print_expr(expr->right,tab+1);
			print_indents(tab);
			puts("</tne>");
			break;
		case less:
			print_indents(tab);
			puts("<less>");
			tree_print_expr(expr->left,tab+1);
			tree_print_expr(expr->right,tab+1);
			print_indents(tab);
			puts("</less>");
			break;
		case leq:
			print_indents(tab);
			puts("<leq>");
			tree_print_expr(expr->left,tab+1);
			tree_print_expr(expr->right,tab+1);
			print_indents(tab);
			puts("</leq>");
			break;
		case greater:
			print_indents(tab);
			puts("<greater>");
			tree_print_expr(expr->left,tab+1);
			tree_print_expr(expr->right,tab+1);
			print_indents(tab);
			puts("</greater>");
			break;
		case geq:
			print_indents(tab);
			puts("<geq>");
			tree_print_expr(expr->left,tab+1);
			tree_print_expr(expr->right,tab+1);
			print_indents(tab);
			puts("</geq>");
			break;
		case and:
			print_indents(tab);
			puts("<and>");
			tree_print_expr(expr->left,tab+1);
			tree_print_expr(expr->right,tab+1);
			print_indents(tab);
			puts("</and>");
			break;
		case or:
			print_indents(tab);
			puts("<or>");
			tree_print_expr(expr->left,tab+1);
			tree_print_expr(expr->right,tab+1);
			print_indents(tab);
			puts("</or>");
			break;
		case not:
			print_indents(tab);
			puts("<not>");
			tree_print_expr(expr->left,tab+1);
			print_indents(tab);
			puts("</not>");
			break;
		case uplus:
			print_indents(tab);
			puts("<uplus>");
			tree_print_expr(expr->left,tab+1);
			print_indents(tab);
			puts("</uplus>");
			break;
		case uminus:
			print_indents(tab);
			puts("<uminus>");
			tree_print_expr(expr->left,tab+1);
			print_indents(tab);
			puts("</uminus>");
			break;
		case arr:
			print_indents(tab);
			puts("<array>");
			tree_print_array_members(expr->arrElements,tab+1);
			print_indents(tab);
			puts("</array>");
			break;
		case new_expr:
			print_indented_string(tab,"<new>");
			if(expr->funcname) {
                print_indents(tab);
				//print_indented_string(tab+1,"<classname>");
                printf("<classname constructor_methodref=\"%d\">\n",expr->constTableIndex);
				print_indented_string(tab+2,expr->funcname);
				print_indented_string(tab+1,"</classname>");

				if(expr->args) {
					print_indented_string(tab+1,"<arglist>");
					tree_print_exprlist(expr->args,tab+2);
					print_indented_string(tab+1,"</arglist>");
				}
			}
			if(expr->varname) {
				print_indented_string(tab+1,"<classname-var>");
				print_indented_string(tab+2,expr->varname);
				print_indented_string(tab+1,"</classname-var>");

				if(expr->args) {
					print_indented_string(tab+1,"<arglist>");
					tree_print_exprlist(expr->args,tab+2);
					print_indented_string(tab+1,"</arglist>");
				}
			}
			print_indented_string(tab,"</new>");
			break;
        case arrowVar:
            print_indented_string(tab,"<arrow-var>");
			tree_print_expr(expr->left,tab+1);

			if(expr->funcname) {
				print_indented_string(tab+1,"<methodname>");
				tree_print_expr(expr->right,tab+2);
				print_indented_string(tab+1,"</methodname>");
			}
			if(expr->fieldname) {
				print_indented_string(tab+1,"<fieldname>");
				tree_print_expr(expr->right,tab+2);
				print_indented_string(tab+1,"</fieldname>");
			}

			if(expr->args) {
				print_indented_string(tab+1,"<arglist>");
				tree_print_exprlist(expr->args,tab+2);
				print_indented_string(tab+1,"</arglist>");
			}
			print_indented_string(tab,"</arrow-var>");
			break;
		case arrow:
			print_indented_string(tab,"<arrow>");
			tree_print_expr(expr->left,tab+1);

			if(expr->funcname) {
				//print_indented_string(tab+1,"<methodname>");
                print_indents(tab+1);
                printf("<methodname methodref=\"%d\">\n",expr->constTableIndex);
				print_indented_string(tab+2,expr->funcname);
				print_indented_string(tab+1,"</methodname>");
			}
			if(expr->fieldname) {
				//print_indented_string(tab+1,"<fieldname>");
                print_indents(tab+1);
                printf("<fieldname fieldref=\"%d\">\n",expr->constTableIndex);
				print_indented_string(tab+2,expr->fieldname);
				print_indented_string(tab+1,"</fieldname>");
			}

			if(expr->args) {
				print_indented_string(tab+1,"<arglist>");
				tree_print_exprlist(expr->args,tab+2);
				print_indented_string(tab+1,"</arglist>");
			}
			print_indented_string(tab,"</arrow>");
			break;
        case arrowassign:
            print_indented_string(tab,"<arrowassign>");
			tree_print_expr(expr->left,tab+1);
            tree_print_expr(expr->right,tab+1);
            print_indented_string(tab,"</arrowassign>");
			break;
		case id_expr:
			//print_indented_string(tab,"<funccall>");
            print_indents(tab);
            printf("<funccall methodref=\"%d\">\n",expr->constTableIndex);

			print_indented_string(tab+1,"<funcname>");
			print_indented_string(tab+2,expr->funcname);
			print_indented_string(tab+1,"</funcname>");
			
			if(expr->args) {
				print_indented_string(tab+1,"<args>");
				tree_print_exprlist(expr->args,tab+2);
				print_indented_string(tab+1,"</args>");
			}
			print_indented_string(tab,"</funccall>");
			
			break;
        case parentmethodcall:
            print_indents(tab);
            printf("<parentmethodcall methodref=\"%d\">\n",expr->constTableIndex);
            print_indented_string(tab+1,expr->funcname);
            print_indented_string(tab,"</parentmethodcall>");
            break;

	}
}
void tree_print_exprlist(struct ExprListInfo* list,int tab) {
	struct ExprInfo* iterator = list->first;
	while(iterator) {
		tree_print_expr(iterator,tab+1);
		iterator=iterator->pNext;
	}
}
void tree_print_array_members(struct ArrMemListInfo* arrElements,int tab) {
    if(!arrElements)
        return;
	struct ArrMemInfo* iterator = arrElements->first;
	while(iterator) {
		print_indents(tab+1);
		puts("<arr_member>");
		if(iterator->key) {
			print_indents(tab+2);
			puts("<key>");
			tree_print_expr(iterator->key,tab+3);
			print_indents(tab+2);
			puts("</key>");
		}
		print_indents(tab+2);
		puts("<value>");
		tree_print_expr(iterator->value,tab+3);
		iterator=iterator->pNext;
		print_indents(tab+2);
		puts("</value>");
		print_indents(tab+1);
		puts("</arr_member>");
	}		
}

void tree_print_if(struct IfStmtInfo* pIfStmt,int tab) {
	print_indents(tab);
	puts("<ifstmt>");
	print_indents(tab+1);
	puts("<if>");
	tree_print_expr(pIfStmt->pExpr,tab+2);
	print_indents(tab+1);
	puts("</if>");

	print_indents(tab+1);
	puts("<truestmt>");
	if(pIfStmt->pStmtLeft)
		tree_print_stmt(pIfStmt->pStmtLeft,tab+2);
	print_indents(tab+1);
	puts("</truestmt>");

	if(pIfStmt->pBlock)
		tree_print_elseiflist(pIfStmt->pBlock,tab+1);

	if(pIfStmt->pStmtRight) {
		print_indents(tab+1);
		puts("<falsestmt>");
		tree_print_stmt(pIfStmt->pStmtRight,tab+2);
		print_indents(tab+1);
		puts("</falsestmt>");
	}

	print_indents(tab);
	puts("</ifstmt>");
}
void tree_print_elseiflist(struct ElseIfListInfo* pBlock,int tab) 
{
	struct ElseIfInfo* iterator = pBlock->pFirst;
	print_indents(tab);
	puts("<elseiflist>");
	while(iterator) {
		tree_print_elseif(iterator,tab+1);
		iterator=iterator->pNext;
	}
	print_indents(tab);
	puts("</elseiflist>");
}
void tree_print_elseif(struct ElseIfInfo* pElseif,int tab) {
	print_indents(tab);
	puts("<elseif>");
	
	tree_print_expr(pElseif->pExpr,tab+1);
	
	print_indents(tab+1);
	puts("<truestmt>");
	if(pElseif->pStmtLeft)
		tree_print_stmt(pElseif->pStmtLeft,tab+2);
	print_indents(tab+1);
	puts("</truestmt>");

	print_indents(tab);
	puts("</elseif>");
}
void tree_print_switch(struct SwitchStmtInfo* switchCase,int tab) {

	print_indents(tab);
	puts("<switch>");
	
		print_indents(tab+1);
		puts("<switch-expr>");
		tree_print_expr(switchCase->pExrp,tab+2);
		print_indents(tab+1);
		puts("</switch-expr>");

		if(switchCase->pCase)
			tree_print_caselist(switchCase->pCase,tab+1);

		if(switchCase->pStmtList) {
			print_indents(tab+1);
			puts("<default-stmt>");
			tree_print_stmtlist(switchCase->pStmtList,tab+2);
			print_indents(tab+1);
			puts("</default-stmt>");
		}

	print_indents(tab);
	puts("</switch>");
}
void tree_print_caselist(struct CaseStmtListInfo* list,int tab) {
	struct CaseInfo* iterator= list->pFirst;
	while(iterator) {
		tree_print_case(iterator,tab+1);
		iterator=iterator->pNext;
	}
}
void tree_print_case(struct CaseInfo* pCase,int tab) {
	print_indents(tab);
	puts("<case>");

	print_indents(tab+1);
	puts("<case-expr>");
	tree_print_expr(pCase->pExpr,tab+2);
	print_indents(tab+1);
	puts("</case-expr>");
	
	if(pCase->pStmtList) {
		print_indents(tab+1);
		puts("<case-stmt>");
		tree_print_stmtlist(pCase->pStmtList,tab+2);
		print_indents(tab+1);
		puts("</case-stmt>");
	}
	print_indents(tab);
	puts("</case>");
}
void tree_print_mainstmt(struct MainStmtInfo* pMsti,int tab) {
	if(pMsti->pFuncDefInfo) {
		tree_print_funcdef(pMsti->pFuncDefInfo,tab);
	}
	if(pMsti->pStmtInfo) {
		tree_print_stmt(pMsti->pStmtInfo,tab);
	}
	if(pMsti->pClassInfo) {
		tree_print_classdef(pMsti->pClassInfo,tab);
	}
}
void tree_print_funcdef(struct FuncDefInfo* fdef,int tab) {
	print_indents(tab);
	puts("<function>");

	print_indents(tab+1);
	puts("<function-name>");
	print_indents(tab+2);
	puts(fdef->id);
	print_indents(tab+1);
	puts("</function-name>");

	if(fdef->pVarList)
		tree_print_varlist(fdef->pVarList,tab+1);

	print_indents(tab+1);
	puts("<function-body>");
	if(fdef->pStmtList)
		tree_print_stmtlist(fdef->pStmtList,tab+2);
	print_indents(tab+1);
	puts("</function-body>");

	print_indents(tab);
	puts("</function>");
}
void tree_print_varlist(struct VarListInfo* vlist,int tab) {
	struct VarInfo* iterator= vlist->pFirst;
	print_indents(tab+1);
	puts("<function-arglist>");
	while(iterator) {
		tree_print_var(iterator,tab+2);
		iterator=iterator->pNext;
	}
	print_indents(tab+1);
	puts("</function-arglist>");
}
void tree_print_var(struct VarInfo* var,int tab) {
	print_indents(tab);
	puts("<function-arg>");
	
	print_indents(tab+1);
    printf("<function-arg-name localTableIndex=\"%d\">\n",var->localTableIndex);
	
	print_indents(tab+2);
	puts(var->Name);

	print_indents(tab+1);
	puts("</function-arg-name>");

	if(var->pDefault) {
		print_indents(tab+1);
		puts("<function-arg-default>");
		
		tree_print_expr(var->pDefault,tab+2);

		print_indents(tab+1);
		puts("</function-arg-default>");
	}
	print_indents(tab);
	puts("</function-arg>");
}
void tree_print_classdef(struct ClassDefInfo* cdef, int tab){
	print_indents(tab);
	puts("<class>");

	print_indents(tab+1);
	puts("<classname>");
	
	print_indents(tab+1);
	puts(cdef->classname);

	print_indents(tab+1);
	puts("</classname>");

	if(cdef->parentname) {
		print_indents(tab+1);
		puts("<parent>");
		
		print_indents(tab+1);
		puts(cdef->parentname);

		print_indents(tab+1);
		puts("</parent>");
	}

	if(cdef->body)
		tree_print_classbody(cdef->body,tab+1);

	print_indents(tab);
	puts("</class>");
}
void tree_print_classbody(struct ClassBodyElementList* pList,int tab) {
	struct ClassBodyElement* iterator = pList->pFirst;
	while(iterator) {
		tree_print_classbodyelement(iterator,tab+1);
		iterator=iterator->pNext;
	}
}
void tree_print_classbodyelement(struct ClassBodyElement* pElement,int tab) {
	if(pElement->pMethod) {
		print_indented_string(tab,"<method>");
	
		print_indented_string(tab+1,"<accesslevel>");
		
		switch(pElement->aclev){
		case Public: print_indented_string(tab+2,"public");
			break;
		case Protected: print_indented_string(tab+2,"protected");
			break;
		case Private: print_indented_string(tab+2,"private");
			break;
		}
		print_indented_string(tab+1,"</accesslevel>");
		tree_print_funcdef(pElement->pMethod,tab+1);


		print_indented_string(tab,"</method>");
	}
	if(pElement->var){
		print_indented_string(tab,"<field>");
	
		print_indented_string(tab+1,"<accesslevel>");
		
		switch(pElement->aclev){
		case Public: print_indented_string(tab+2,"public");
			break;
		case Protected: print_indented_string(tab+2,"protected");
			break;
		case Private: print_indented_string(tab+2,"private");
			break;
		}
		print_indented_string(tab+1,"</accesslevel>");
		print_indented_string(tab+1,"<fieldname>");
		print_indented_string(tab+2,pElement->var);
		print_indented_string(tab+1,"</fieldname>");


		print_indented_string(tab,"</field>");
	}
}